import { defineStore } from "pinia";
import { getHotSuggests, getHotCate, getHouseList } from "../../services";

const useHomeStore = defineStore("home", {
  state: () => ({
    hotSuggests: [],
    hotCategories: [],
    houseList: [],
    currentPage: 1,
  }),
  actions: {
    async fetchHotSuggests() {
      const res = await getHotSuggests();
      this.hotSuggests = res.data;
    },
    async fetchHotCate() {
      const res = await getHotCate();
      this.hotCategories = res.data;
    },
    async fetchHouseList() {
      const res = await getHouseList(this.currentPage);
      this.houseList.push(...res.data);
      this.currentPage++;
    },
  },
});

export default useHomeStore;
